﻿
namespace Slc.Core.Entity
{
    public class OQL2 : OQL4, IOQL2
    {
        private OQL CurrentOQL;
        public OQL2(OQL oql)
            : base(oql)
        {
            CurrentOQL = oql;
        }
        public OQL2(EntityBase e)
            : base(e)
        {
            CurrentOQL = new OQL(e);
        }
        public OQL3 GroupBy(object field)
        {
            string fieldName = CurrentOQL.TakeOneStackFields().SqlFieldName;
            CurrentOQL.GroupbyFieldNames.Add(fieldName.Trim());
            CurrentOQL.oqlString += "\r\n          GROUP BY " + fieldName;
            return new OQL3(CurrentOQL);
        }

        public OQL3 GroupBy(object field, params object[] others)
        {
            string strTemp = string.Empty;
            string fieldName = CurrentOQL.TakeOneStackFields().SqlFieldName;
            CurrentOQL.GroupbyFieldNames.Add(fieldName.Trim());

            for (int i = 0; i < others.Length; i++)
            {
                string fieldNameTemp = CurrentOQL.TakeOneStackFields().SqlFieldName;
                CurrentOQL.GroupbyFieldNames.Add(fieldNameTemp.Trim());
                strTemp += "," + fieldNameTemp;
            }

            CurrentOQL.oqlString += "\r\n          GROUP BY " + fieldName + strTemp;
            return new OQL3(CurrentOQL);
        }
        public OQL4 Having(object field, object Value, string sqlFunctionFormat)
        {
            OQL3 q3 = new OQL3(CurrentOQL);
            return q3.Having(field, Value, sqlFunctionFormat);
        }

        public OQL4 Having(OQLCompareFunc cmpFun)
        {
            OQL3 q3 = new OQL3(CurrentOQL);
            return q3.Having(cmpFun);
        }

    }
}
